<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
	/**
	 * [$fillable 可写入字段]
	 * @var [type]
	 */
	protected $fillable = ['name','description','picture', 'user_id'];



	/**
	 * 添加产品
	 * @param  [type]  $data  [产品数据]
	 * @param  boolean $flash [boolval(var)]
	 * @return [type]         [boolval(var)]
	 */
	public function storeData($data)
	{
		// 处理data为空的情况
        if (empty($data)) {
            return false;
        }
        //添加数据
        $result = $this->create($data);
        if ($result) {
            return $result->id;
        }else{
            return false;
        }
	}


    public function option()
    {
        return $this->hasMany(Option::class);
    }


    public function user()
    {
        return $this->belongsTo(User::class);
    }























}
